package Server.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;

@Data
@Entity
@EntityListeners(AuditingEntityListener.class)
public class RequestLog {
    @Id
    @GeneratedValue(generator = "UuidProduce")
    @GenericGenerator(name="UuidProduce", strategy="Server.tool.UuidProduce")
    private String uuid;
    @Lob
    @Column
    private String jsJson;
    @Lob
    @Column
    private String fhJson;
    @Lob
    @Column
    private String headers;

    @Column
    private String apiName;

    @CreatedDate
    @Column
    private Date createTime;

    @Column
    private String ip;

    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum Status {
        NO("失败"),
        YES("成功");
        Status(String display) {
            this.display = display;
        }
        private String display;

        public String getDisplay() {
            return display;
        }

        public void setDisplay(String display) {
            this.display = display;
        }
    }
    @Enumerated(EnumType.STRING)
    @Column
    private Status status;

    @ManyToOne
    @JoinColumn(name = "authorId")
    private Users author;

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getJsJson() {
        return jsJson;
    }

    public void setJsJson(String jsJson) {
        this.jsJson = jsJson;
    }

    public String getFhJson() {
        return fhJson;
    }

    public void setFhJson(String fhJson) {
        this.fhJson = fhJson;
    }

    public String getHeaders() {
        return headers;
    }

    public void setHeaders(String headers) {
        this.headers = headers;
    }

    public String getApiName() {
        return apiName;
    }

    public void setApiName(String apiName) {
        this.apiName = apiName;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    public Users getAuthor() {
        return author;
    }

    public void setAuthor(Users author) {
        this.author = author;
    }
}
